#!/usr/bin/python
# -*- coding:utf-8 -*-
#获取5,10,15分钟的负载
import os ,time
from cpu_load import cpu_percent

"""
#获取cpu多个key指标的时候用for打出
#def sub_dict(form_dict, sub_keys, default=None): 
#    return dict([(k, form_dict.get(k.strip(), default)) for k in sub_keys.split(',')]) 
#def read_cpuinfo(): 
#    cpu_stat = [] 
#    with open('/proc/cpuinfo', 'r') as f: 
#        data = f.read() 
#        for line in data.split('\n\n'): 
#            cpu_stat.append(line) 
#    return cpu_stat[-2] 
#cpuinfo = get_cpuinfo(read_cpuinfo())
"""

def get_cpuinfo(data): 
    cpu_info = {} 
    for i in data.splitlines(): 
        k, v = [x.strip() for x in i.split(':')] 
        cpu_info[k] = v 
        
    cpu_info['physical id'] = str(int(cpu_info.get('physical id')) + 1) 
    #return sub_dict(cpu_info, 'model name,physical id,cpu cores') 
    return cpu_info.get("cpu cores")


def cpu_post():
    cpu_load = "".join(tuple(os.popen('uptime', 'r').read().strip('\n').split(" ")[-3::]))
    return cpu_load + "," + str(cpu_percent()) 

if __name__ == '__main__':
    print cpu_post()
